/*
 * Copyright (c) 2008, Xiong Yingfei, the University of Tokyo
 * All rights reserved.
 */
package ac.jp.u_tokyo.SyncLib.util;

import java.util.Iterator;

public class TwoIterable<K> implements Iterable
{
	Iterable<K> _first;

	Iterable<K> _second;

	public TwoIterable(Iterable<K> first, Iterable<K> second)
	{
		super();
		_first = first;
		_second = second;
	}

	public Iterator<K> iterator()
	{
		return new TwoIterator(_first.iterator(), _second.iterator());
	}

	@Override
	public String toString()
	{
		StringBuilder result = new StringBuilder();
		result.append('[');
		for (Object k : this) {
			result.append(k);
			result.append(',');
		}
		result.append(']');
		return result.toString();
	}
	
	

}

class TwoIterator<K> implements Iterator
{

	Iterator<K> _first;

	Iterator<K> _second;

	public TwoIterator(Iterator<K> first, Iterator<K> second)
	{
		super();
		_first = first;
		_second = second;
	}

	public boolean hasNext()
	{
		if (_first.hasNext())
			return true;
		else
			return _second.hasNext();
	}

	public K next()
	{
		if (_first.hasNext())
			return _first.next();
		else
			return _second.next();
	}

	public void remove()
	{}
}